package com.tuanzi.webtalk.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;


/**
 * 雄关漫道真如铁，而今迈过从头越
 **/

/**
 * 字符编码过滤器
 */

@Configuration
public class EnCodingFilterConfig {

    @Bean
    public FilterRegistrationBean filterRegistrationBean(){
        FilterRegistrationBean bean = new FilterRegistrationBean();

        //使用框架中的过滤器类
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        //指定使用的编码方式
        filter.setEncoding("utf-8");
        //指定请求request和应答response对象都使用encoding的值
        filter.setForceEncoding(true);

        bean.setFilter(filter);
        bean.addUrlPatterns("/*");

        return bean;
    }

}
